
package datolib;

public class TevMessage {
	
	private String function;
	private ParameterList parameters;
	
	private Class<?>[] classes;
	private Object[] objects;
	
	public TevMessage(String func) {
		this.function = func;
		this.parameters = new ParameterList();
		
		this.classes = null;
		this.objects = null;
	}	
	
	public String function() {
		return this.function;
	}
	
	public void addParameter(String type, String value) {
		this.parameters.add(DataType.fromString(type), value);
	}
	
	public void load() {
	
		this.classes = new Class<?>[this.parameters.length()];
		this.objects = new Object[this.parameters.length()];
		
		for (int i = 0;i < this.parameters.length(); i++) {
			Parameter param = this.parameters.get(i);
			
			switch (param.dataType()) {
				case STRING:
					this.classes[i] = String.class;
					this.objects[i] = param.value();
					break;
				case INT:
					this.classes[i] = Integer.class;
					this.objects[i] = Integer.parseInt(param.value());
					break;
				case DOUBLE:
					this.classes[i] = Double.class;
					this.objects[i] = Double.parseDouble(param.value());
					break;
				case BOOL:
					this.classes[i] = Boolean.class;
					this.objects[i] = Boolean.parseBoolean(param.value());
					break;
				default:
					this.classes[i] = Object.class;
					this.objects[i] = null;
					break;
			}
		}
		
	}
	
	public Class<?>[] getClasses() {
		return this.classes;
	}
	
	public Object[] getObjects() {
		return this.objects;
	}
	
}
